package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.DateUtil;
import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

//游记推荐
@Setter@Getter
public class TravelCommend extends BaseDomain {
    public static final Integer TYPE_WEEK = 1; //每周
    public static final Integer TYPE_MONTH = 2; //每月
    public static final Integer TYPE_STRATEGY = 3; //攻略

    private Long travelId; //推荐的游记ID

    private String title; //包装标题

    private String subTitle; //包装副标题

    private String coverUrl; //包装封面

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date schedule; //推荐时间

    private Integer type = TYPE_WEEK; //推荐类型

    /*//根据实际需求添加的
    private User author; //作者
    private String placeName; //地点名称*/

    public String getTypeName() {
        String msg = "每周推荐";
        if (type == TYPE_MONTH) {
            msg = "每月推荐";
        } else if (type == TYPE_STRATEGY) {
            msg = "攻略推荐";
        }
        return msg;
    }

    public String getJson() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("travelId", travelId);
        map.put("title", title);
        map.put("subTitle", subTitle);
        map.put("coverUrl", coverUrl);
        map.put("schedule", DateUtil.formatDate(schedule));
        map.put("type", type);
        return JSONUtil.toJSONString(map);
    }
}